<template>
  <section>
    <div class="bii-box-section">
      <el-form :inline="true" :model="listQuery" style="margin-top:20px;">
        <el-form-item label="">
          <el-date-picker value-format="yyyy-MM-dd" size="mini" v-model="date" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="">
          <el-select class="w100" size="mini" v-model="listQuery.type" placeholder="提现状态" clearable>
            <el-option label="申请中" value="0"></el-option>
            <el-option label="已通过" value="1"></el-option>
            <el-option label="已拒绝" value="2"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="">
          <common-input style="width:150px;" placeholder="供应商" v-model="listQuery.agencyName" />
        </el-form-item>
        <el-form-item>
          <el-input size="mini" placeholder="流水号" v-model="listQuery.orderNo" />
        </el-form-item>
        <el-form-item>
          <el-button size="mini" type="primary" @click="handleFilter">查询</el-button>
        </el-form-item>
      </el-form>

      <el-table ref="dataTable" :data="list" style="width: 100%">
        <el-table-column align="left" label="流水号" width="180">
          <template slot-scope="scope">
            <span>{{ scope.row.orderNo }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="供应商" width="150">
          <template slot-scope="scope">
            <span>{{ scope.row.agencyName }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="申请时间" width="150">
          <template slot-scope="scope">
            <span>{{ scope.row.createTime }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="处理时间" width="150">
          <template slot-scope="scope">
            <span>{{ scope.row.updateTime }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="账户名">
          <template slot-scope="scope">
            <span>{{ scope.row.withdrawHost }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="开户行">
          <template slot-scope="scope">
            <span>{{ scope.row.withdrawName }}</span>
          </template>
        </el-table-column>
        <el-table-column align="left" label="账户">
          <template slot-scope="scope">
            <span>{{ scope.row.withdrawAccount }}</span>
          </template>
        </el-table-column>
        <el-table-column align="right" label="申请金额" width="100">
          <template slot-scope="scope">
            <span>￥{{ scope.row.moneyApply }}</span>
          </template>
        </el-table-column>
        <el-table-column align="right" label="到账金额" width="100">
          <template slot-scope="scope">
            <span>￥{{ scope.row.money }}</span>
          </template>
        </el-table-column>
        <el-table-column align="center" label="凭证">
          <template slot-scope="scope">
            <img v-if="scope.row.imgUrl" :src="scope.row.imgUrl | thumbnail" :data-origin="scope.row.imgUrl"
              class="img-thumbnail" width="60" />
          </template>
        </el-table-column>
        <el-table-column align="right" label="状态" width="200">
          <template slot-scope="scope">
            <span>{{ scope.row.statusText }}</span>
            <p v-if="scope.row.reason" style="color:red;">{{ scope.row.reason }}</p>
          </template>
        </el-table-column>
        <el-table-column fixed="right" align="center" label="操作" width="120">
          <template slot-scope="scope">
            <span>
              <el-button v-if="scope.row.canDo == 1" type="text" @click="handleCheck(scope.row)">处理</el-button>

            </span>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination-container">
        <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
          :current-page.sync="listQuery.pageNum" :page-sizes="[20, 30, 50]" :page-size="listQuery.pageSize"
          layout="total, sizes, prev, pager, next, jumper" :total="total"> </el-pagination>
      </div>
    </div>
    <el-dialog title="提现处理" :visible.sync="dialogFormVisible" :close-on-click-modal="false" width="500px"
      @close="dialogClose">
      <el-form :model="form" ref="form" label-width="150px">
        <el-form-item label="操作类型" prop="type">
          <el-radio-group v-model="form.type">
            <el-radio :label="1">通过</el-radio>
            <el-radio :label="2">驳回</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="申请提现" prop="moneyApply">
          ￥{{ form.moneyApply }}
        </el-form-item>
        <el-form-item label="实际到账" prop="money" v-if="form.type == 1">
          <el-input size="mini" type="number" placeholder="请输入实际到账金额" v-model="form.money" />
        </el-form-item>
        <el-form-item label="上传凭证" prop="imgUrl">
          <pic-sel style="float:left" v-model="form.imgUrl" />
        </el-form-item>
        <el-form-item label="备注" prop="reason">
          <common-input type="textarea" :autosize="{ minRows: 3, maxRows: 5 }" placeholder="拒绝审核时必填" maxlength="100"
            v-model="form.reason" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" @click="cancel('form')">取消</el-button>
        <el-button :loading="checkLoading" size="mini" type="primary" @click="check('form')">确定</el-button>
      </div>
    </el-dialog>

  </section>
</template>

<script>
import {
  agency_withdraw_list,
  agency_withdraw_do
} from '../../api/partner';
export default {
  components: {
    'pic-sel': () => import('../../components/PicSel/index')
  },
  data() {
    return {
      dialogFormVisible: false,
      listQuery: {
        startDate: undefined,
        endDate: undefined,
        type: undefined,
        pageNum: 1,
        pageSize: 20,
        agencyName: undefined,
        orderNo: undefined,
      },
      list: [],
      total: 0,
      date: undefined,
      form: {
        id: undefined,
        type: 1,
        reason: undefined,
        money: undefined,
        moneyApply: undefined,
        imgUrl: undefined,
      }
    }
  },
  mounted() {

  },
  created() {
    this.handleFilter();
  },
  methods: {
    dialogClose() {
      this.$refs.form.resetFields();
    },
    cancel(formName) {
      this.dialogFormVisible = false;
      this.$refs[formName].resetFields();
    },
    check(formName) {
      this.form.reason = $.trim(this.form.reason)

      // console.log(this.form)
      if (this.form.type == 2) {
        if (this.form.reason.length < 1) {
          this.$message.error("拒绝时备注必填");
          return;
        }
      }

      this.$confirm('确定提交提现申请处理?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          this.checkLoading = true;
          agency_withdraw_do(this.form).then((res) => {

            this.checkLoading = false;
            this.$message.success("提现申请已处理");
            this.dialogFormVisible = false;
            this.getList();
          }).catch((err) => {
            this.checkLoading = false;

          })
        }).catch(() => { });
    },
    handleCheck(row) {
      this.form.id = row.id;
      this.form.type = 1;
      this.form.reason = "";
      this.form.imgUrl = undefined;
      this.form.money = row.money;
      this.form.moneyApply = row.moneyApply;

      this.dialogFormVisible = true;
    },
    handleFilter() {
      this.listQuery.pageNum = 1;
      this.getList();
    },
    handleSizeChange(val) {
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },
    getList() {
      if (this.date) {
        this.listQuery.startDate = this.date[0];
        this.listQuery.endDate = this.date[1];
      } else {
        this.listQuery.startDate = undefined;
        this.listQuery.endDate = undefined;
      }

      agency_withdraw_list(this.listQuery).then((response) => {
        this.list = response.data.list;
        this.total = response.data.total;

      }).catch((err) => {

      })
    },
  }
};
</script>
<style lang="scss" scoped>
.bii-box-section {
  // padding: 80px;
  height: 100%;
  background: #fff;
  -webkit-box-sizing: border-box;
  box-sizing: border-box;
  overflow: auto;

  .bd-head {
    position: relative;

    .head-price {
      font-size: 14px;
      display: -webkit-box;
      display: -ms-flexbox;
      display: flex;
      -webkit-box-align: center;
      -ms-flex-align: center;
      align-items: center;
      line-height: 16px;
      text-align: center;
      margin-bottom: 30px;

      .num {
        font-size: 34px;
        line-height: 36px;
      }

      .line {
        height: 66px;
        width: 1px;
        background: #d8d8d8;
        margin: 0 75px;
      }
    }
  }

  .bind-card {
    position: absolute;
    top: 0;
    right: 80px;
    border-radius: 4px;
    background: rgba(36, 97, 241, .05);
    padding: 34px;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
    font-size: 16px;

    .bank-msg {
      margin-right: 34px;

      .num {
        font-size: 14px;
        color: #666;
        line-height: 18px;
      }
    }
  }
}
</style>
